package com.mjk.common.web.getway.restful.interceptor.type.commons.impl;


import com.mjk.common.base.response.BeeResponse;
import com.mjk.common.tools.interceptor.InterceptorChain;
import com.mjk.common.web.getway.constns.GetWayError;
import com.mjk.common.web.getway.constns.GetwayConsts;
import com.mjk.common.web.getway.restful.interceptor.GetWayInterceptorReq;
import com.mjk.common.web.getway.restful.interceptor.annotation.BeeGetWayInterceptor;
import com.mjk.common.web.getway.restful.interceptor.type.GetWayInterceptor;
import com.mjk.common.web.getway.restful.interceptor.type.GetWayInterceptorType;
import com.mjk.common.web.getway.utils.WebUtil;
import org.springframework.util.ObjectUtils;

/**
 * 获取IP地址
 * @author Administrator
 *
 */
@BeeGetWayInterceptor(value=6,interceptorType={GetWayInterceptorType.ALL})
public class GetWayIpInterceptor implements GetWayInterceptor {
	@Override
	public BeeResponse interceptor(GetWayInterceptorReq request,
								   InterceptorChain<GetWayInterceptorReq, BeeResponse> next) {
		String ip = WebUtil.getIpAddr(request.getRequest());
		if(ObjectUtils.isEmpty(ip)) {
			return GetWayError.IP_IS_NULL.tranceError("");
		}
		request.getParams().put(GetwayConsts.IP, ip);
		return next.proceed(request);
	}
}
